'use strict';

const { Controller } = require('egg');
const OSS = require('ali-oss');
const client = new OSS({
  region: 'oss-cn-beijing',
  accessKeyId: 'LTAI5tJP6QUxCvNNyyvb87pG',
  accessKeySecret: 'd9sEJaspK8Axz1vU7ysrJMvfiECPUW',
  bucket: 'bander03'
});
class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    const results = await this.app.mysql.select('image');
    ctx.body = {
      code:200,
      data:results
    }
  }
  async upload(){
    const { ctx } = this;
    let file = ctx.request.files[0];
    let data = await client.put(file.filename,file.filepath)
    console.log(data);
    await this.app.mysql.insert('image', { image: data.url });
    ctx.body = {
      code:200,
    }
  }
}

module.exports = HomeController;
